package com.lzm.back.controller;

import com.github.pagehelper.PageInfo;
import com.lzm.back.common.MyResult;
import com.lzm.back.entity.EventCategory;
import com.lzm.back.service.EventCategoryService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/eventCategory")
public class EventCategoryController {

    @Resource
    private EventCategoryService service;

    //增加
    @PostMapping("/postEventCategory")
    public MyResult postEventCategory(@RequestBody EventCategory eventCategory) {

        System.out.println(eventCategory);
        service.postEventCategory(eventCategory);
        return MyResult.success(eventCategory);
    }


    //删除单个
    @DeleteMapping("/{id}")
    public MyResult delEventCategory(@PathVariable Long id) {

        service.delEventCategory(id);
        return MyResult.success();
    }


    //批量删除
    @DeleteMapping("/batch")
    public MyResult delEventCategoryBaTch(@RequestBody List<Long> ids) {

        service.delEventCategoryBaTch(ids);
        return MyResult.success();
    }

    //修改
    @PutMapping("/putEventCategory")
    public MyResult putEventCategory(@RequestBody EventCategory eventCategory) {
        service.putEventCategory(eventCategory);
        return MyResult.success(eventCategory);

    }

    @GetMapping("/listAll")
    public MyResult listAll() {
        List<EventCategory> list = service.listAll();
        return MyResult.success(list);
    }

    @GetMapping("/SelectPage")
    public MyResult SelectPage(EventCategory eventCategory,
                               @RequestParam String name,//赛事类别名

                               @RequestParam(defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize
    ) {

        PageInfo<EventCategory> eventCategoryPageInfo = service.selectPage(eventCategory, name, pageNum, pageSize);

        return MyResult.success(eventCategoryPageInfo);
    }


}
